<template>
  <div class="home" style="height: 100%">
    <el-container style="min-height:100vh ">
      <el-aside width="sideWidth+'px'" height="200px" style="background-color: rgb(238, 241, 246)">
        <el-menu :default-openeds="['1', '3']" style="height:100%"
                 :collapse="isCollapse"
                 background-color="#304156"
                 text-color="#fff"
                 active-text-color="#ffd04b"
                 :collapse-transition="false"
                 class="el-menu-vertical-demo">
          <div style="height:60px; line-height:60px;text-align:center;">
            <img src="../assets/logo.png" alt=""style=";width:20px;position:relative;top:5px;" />
            <b style="color: #fff;"v-show="logoTextShow">程序员进阶服务站</b>
          </div>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-message"></i>
              <span slot="title">导航一</span>
            </template>
            <el-menu-item-group>
              <template slot="title">分组一</template>
              <el-menu-item index="1-1">选项1</el-menu-item>
              <el-menu-item index="1-2">选项2</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="分组2">
              <el-menu-item index="1-3">选项3</el-menu-item>
            </el-menu-item-group>
            <el-submenu index="1-4">
              <template slot="title">选项4</template>
              <el-menu-item index="1-4-1">选项4-1</el-menu-item>
            </el-submenu>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span slot="title">导航二</span>
            </template>
            <el-menu-item-group>
              <template slot="title">分组一</template>
              <el-menu-item index="2-1">选项1</el-menu-item>
              <el-menu-item index="2-2">选项2</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="分组2">
              <el-menu-item index="2-3">选项3</el-menu-item>
            </el-menu-item-group>
            <el-submenu index="2-4">
              <template slot="title">选项4</template>
              <el-menu-item index="2-4-1">选项4-1</el-menu-item>
            </el-submenu>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-setting"></i>
              <span slot="title">导航三</span>
            </template>
            <el-menu-item-group>
              <template slot="title">分组一</template>
              <el-menu-item index="3-1">选项1</el-menu-item>
              <el-menu-item index="3-2">选项2</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="分组2">
              <el-menu-item index="3-3">选项3</el-menu-item>
            </el-menu-item-group>
            <el-submenu index="3-4">
              <template slot="title">选项4</template>
              <el-menu-item index="3-4-1">选项4-1</el-menu-item>
            </el-submenu>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header style=" font-size: 12px;border-bottom: 3px solid #eee;line-height: 60px ;display: flex">
          <div style="flex:1; font-size:20px">
            <span :class="collapseBtn" style="cursor:pointer" @click="collapse "></span>
          </div>
          <el-dropdown style="width:70px;cursor:pointer">
            <span>王小虎</span><i class="el-icon-arrow-down" style="margin-left:5px"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>个人信息</el-dropdown-item>
              <el-dropdown-item>退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

        </el-header>

        <el-main>
          <div style="margin-bottom: 30px;">
            <el-breadcrumb separator="/" >
              <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item><a href="/">帖子管理</a></el-breadcrumb-item>
            </el-breadcrumb>
          </div>
          <div style="margin: 10px 0;">
            <el-input style="width: 200px"suffix-icon="el-icon-search" placeholder="请输入发布者" class="ml-5" v-model="username" ></el-input>
<!--            <el-input style="width: 200px"suffix-icon="el-icon-search" placeholder="请输入发布者" class="ml-5" ></el-input>-->
<!--            <el-input style="width: 200px"suffix-icon="el-icon-search" placeholder="请输入帖子信息" class="ml-5" ></el-input>-->
            <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
          </div>
          <div style="margin: 10px 0;">
            <el-button  type="primary">发布帖子<i class="el-icon-circle-plus-outline"></i></el-button>
            <el-button  type="danger">批量删除<i class="el-icon-delete-solid"></i></el-button>
          </div>
          <el-table :data="tableData" border stripe>
            <el-table-column prop="create_time" label="日期" width="140">
            </el-table-column>
            <el-table-column prop="username" label="发布者" width="120">
            </el-table-column>
            <el-table-column prop="nickname" label="帖子信息">
            </el-table-column>
            <el-table-column>
              <template >
                <el-button type="success" >编辑<i class="el-icon-edit"></i></el-button>
                <el-button type="danger" >删除<i class="el-icon-delete"></i></el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="block" style="padding: 10px 0;">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNum"
                :page-sizes="[2,5,10,20]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
          </div>

        </el-main>
      </el-container>
    </el-container>
  </div>
<!--  <el-tabs v-model="activeName" @tab-click="handleClick">-->
<!--    <el-tab-pane label="用户管理" name="first">用户管理</el-tab-pane>-->
<!--    <el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>-->
<!--    <el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>-->
<!--    <el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane>-->
<!--  </el-tabs>-->
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

export default {
  name: 'HomeView',
  components: {
    HelloWorld
  },
  data() {
    return {
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 2,
      username: '',
      collapseBtn: 'el-icon-s-fold',
      isCollapse: false,
      sideWidth: 200,
      logoTextShow: true
    }
  },
  created() {
    this.load();
  },
  methods: {
    collapse() {//点击收缩按钮触发
      this.isCollapse = !this.isCollapse;
      if (this.isCollapse) {//收缩
        this.sideWidth = 65;
        this.collapseBtn = 'el-icon-s-unfold';
        this.logoTextShow = false;
      } else {//展开
        this.sideWidth = 200;
        this.collapseBtn = 'el-icon-s-fold';
        this.logoTextShow= true;
      }
    },
    load(){
      //res => res.json()将返回的数据转换为json格式
      fetch('http://localhost:8081/users/page?pageNum='+this.pageNum+'&pageSize='+this.pageSize+"&username="+this.username)//this.
          .then(res => res.json()).then(res => {
        console.log(res)
        this.tableData = res.data
        this.total = res.total
      })
    },
    handleSizeChange(pageSize){
      console.log(pageSize)
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum){
      console.log(pageNum)
      this.pageNum = pageNum
      this.load()
    }
  }
}
</script>
